package cn.ffcs.uec.common.util;

import java.util.ArrayList;
import java.util.List;

import cn.ffcs.uec.common.manager.CustomFilesManager;
import cn.ffcs.uec.common.vo.UecBdDefdoc;
import cn.ffcs.uec.common.vo.UecBdPsncl;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.NodeVo;

public class NodeVoUtil {

	private static CustomFilesManager customFilesManager = (CustomFilesManager) ApplicationContextUtil
			.getBean("customFilesManager");
	
	/**
	 * 通过pkDefdocList在UecBdDefdoc表中查出这个类别的所有可选项，并赋值到bean上
	 */
	public static List<NodeVo> getDictionaries(String pkDefdocList) {
		List<NodeVo> nodeList = new ArrayList<NodeVo>();
		if (!StrUtil.isEmpty(pkDefdocList)) {
			List<UecBdDefdoc> List = customFilesManager.findCustomFilesByPkdefdocList(pkDefdocList);
			for (UecBdDefdoc uecBdDefdoc : List) {
				NodeVo nodeVo = new NodeVo();
				nodeVo.setId(uecBdDefdoc.getPkDefdoc());
				nodeVo.setName(uecBdDefdoc.getName());
				nodeList.add(nodeVo);
			}
			return nodeList;
		}
		return null;
	}
	
	/**
	 * 通过pkDefdocList和pid在UecBdDefdoc表中查出这个类别的所有可选项，并赋值到bean上
	 */
	public static List<NodeVo> getDictionaries(String pkDefdocList,String pid) {
		List<NodeVo> nodeList = new ArrayList<NodeVo>();
		if (!StrUtil.isEmpty(pkDefdocList)) {
			List<UecBdDefdoc> List = customFilesManager.findCustomFilesByPkdefdocList(pkDefdocList);
			for (UecBdDefdoc uecBdDefdoc : List) {
				if(pid.equals(uecBdDefdoc.getPid())) {
					NodeVo nodeVo = new NodeVo();
					nodeVo.setId(uecBdDefdoc.getPkDefdoc());
					nodeVo.setName(uecBdDefdoc.getName());
					nodeList.add(nodeVo);
				}
			}
			return nodeList;
		}
		return null;
	}
	
	
	/**
	 * 通过pkOrg在UecBdPsncl表中查出这个类别的所有可选项，并赋值到bean上
	 */
	public static List<NodeVo> getDictionariesPsncl(String pkOrg) {
		List<NodeVo> nodeList = new ArrayList<NodeVo>();
		if (!StrUtil.isEmpty(pkOrg)) {
			List<UecBdPsncl> List = customFilesManager.findUecUecBdPsnclByUecBdPsnclList(pkOrg);
			for (UecBdPsncl uecBdPsncl : List) {
				NodeVo nodeVo = new NodeVo();
				nodeVo.setId(uecBdPsncl.getPkPsncl());
				nodeVo.setName(uecBdPsncl.getName());
				nodeList.add(nodeVo);
			}
			return nodeList;
		}
		return null;
	} 
	
	
}
